/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package com.broker.provider.base;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import me.send.broker.entity.Configuration;
import me.send.broker.mapper.BrokerEvaluateMapper;
import me.send.broker.mapper.BrokerMapper;
import me.send.broker.mapper.ComplainMapper;
import me.send.broker.mapper.ConfigurationMapper;
import me.send.broker.mapper.MessageMapper;
import me.send.broker.mapper.OpencityMapper;
import me.send.broker.mapper.OrderMapper;
import me.send.broker.mapper.OrderProgressMapper;
import me.send.broker.mapper.PhonenumberMapper;
import me.send.broker.mapper.SysconfigMapper;
import me.send.broker.mapper.UserEvaluateMapper;
import me.send.broker.mapper.UserMapper;
import me.send.broker.mapper.VersionMapper;
import me.send.broker.mapper.WalletMapper;
import me.send.business.base.ErrorEntity;
import me.send.business.base.SendVariable;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author maxmin
 *
 * @date 2015年8月4日 上午10:12:00
 */
public class BaseService {
	@Autowired
	protected PhonenumberMapper phonenumberMapper;

	@Autowired
	protected ConfigurationMapper configurationMapper;
	
	@Autowired
	protected BrokerMapper brokerMapper;
	
	@Autowired
	protected OrderMapper orderMapper;
	
	@Autowired
	protected WalletMapper walletMapper;
	
	@Autowired
	protected ComplainMapper complainMapper;
	
	@Autowired
	protected MessageMapper messageMapper;
	
	@Autowired
	protected BrokerEvaluateMapper brokerEvaluateMapper;
	
	@Autowired
	protected UserEvaluateMapper userEvaluateMapper;
	
	@Autowired
	protected UserMapper userMapper;
	
	@Autowired
	protected OpencityMapper opencityMapper;
	
	@Autowired
	protected SysconfigMapper sysconfigMapper;
	
	@Autowired
	protected VersionMapper versionMapper;
	
	@Autowired
	protected OrderProgressMapper orderProgressMapper;
	
	protected Map<String, Object> configuration;
	
	protected void initialization(){
		if (configuration == null) {
			// 如果还没有加载过 那么首先实例化一下 2015年6月2日17:53:31
			configuration = new HashMap<String, Object>();
			// 加载所有的配置的项目 到map下面
			List<Configuration> list_all = configurationMapper.list_all();
			// 便利下面所有的选项 2015年6月2日17:55:15
			for (Configuration con : list_all) {
				configuration.put(con.getConfigkey(), con.getConfigvalue());
			}
		}
	}
	
	/**
	 * 查看这个tasken是否在数据库存在 在每个调用api的方法 都需要使用 2015年5月26日17:52:31 传过来的key
	 * 是base64加密后的 *
	 */
	protected boolean isDevicenumber(String devicenumber) {
		// 判断这个devicenumber是否存在
		if (devicenumber != null && !"".equals(devicenumber)) {
			if (phonenumberMapper.count_devicenumber(devicenumber) > 0) {
				return true;
			} else {
				return false;
			}
		}
		return false;
	}
	
	/**
	 * 获取 定义到 哪一个 配置 对象 单个 2015年6月3日09:19:13
	 */
	protected Object getConfigurationValue(String key) {
		initialization();
		// 根据key获取到value的值 通过配置表 2015年6月3日09:20:19
		return configuration.get(key);
	}
	
	/**
	 * 返回验证码
	 */
	protected ErrorEntity getErrorEntity(String value) {
		return SendVariable.errorEntityMap.get(value);
	}
}
